﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExtensionMethodDemo
{
    public class Program
    {
        private static void Main(string[] args)
        {
            // Declare an instance of class A, class B, and class C.
            var a = new A();
            var b = new B();
            var c = new C();

            // For a, b, and c, call the following methods: 
            //      -- MethodA with an int argument 
            //      -- MethodA with a string argument 
            //      -- MethodB with no argument. 

            // A contains no MethodA, so each call to MethodA resolves to  
            // the extension method that has a matching signature.
            a.MethodA(1); // Extension.MethodA(object, int)

            // A has a method that matches the signature of the following call 
            // to MethodB.
            a.MethodB(); // A.MethodB() 

            // B has methods that match the signatures of the following 
            // method calls.
            b.MethodA(1); // B.MethodA(int)
            b.MethodB(); // B.MethodB() 

            // B has no matching method for the following call, but  
            // class Extension does.
            b.MethodA("hello"); // Extension.MethodA(object, string) 

            // C contains an instance method that matches each of the following 
            // method calls.
            c.MethodA(1); // C.MethodA(object)
            c.MethodA("hello"); // C.MethodA(object)
            c.MethodB(); // C.MethodB()
            Console.ReadLine();
        }

    }
}
